package com.system.manager.modules.risk.controller;


import com.system.manager.common.annotation.PreAuthorize;
import com.system.manager.common.entity.Result;
import com.system.manager.modules.authorized.enums.SubjectType;
import com.system.manager.modules.risk.dto.FlowVo;
import com.system.manager.modules.risk.dto.StaffStationVo;
import com.system.manager.modules.risk.entity.RiskType;
import com.system.manager.modules.risk.entity.TbFlow;
import com.system.manager.modules.risk.service.IStaffStationService;
import com.system.manager.modules.risk.service.ITbFlowService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author yxp
 * @since 2021-11-15
 */
@Slf4j
@Api(tags = "上传业务")
@RestController
@RequestMapping("/risk/tb-flow/")
public class TbFlowController {
    @Autowired
    private ITbFlowService iTbFlowService;

    @ApiOperation("添加新的业务")
    @PreAuthorize({SubjectType.SYSTEM_ADMIN,SubjectType.RISK_ADMIN})
    @PostMapping("addFlow")
    public void addFlow(@RequestBody FlowVo flowVo){
        iTbFlowService.insertFlow(flowVo);
    }


    /**
     * 获取业务流程
     * @return
     */
    @ApiOperation("获取所有的业务流程")
    @PreAuthorize({SubjectType.SYSTEM_ADMIN,SubjectType.RISK_ADMIN})
    @GetMapping("list")
    public Result riskFlowList() {
        try {
            // 获取所有的风险类型
            List<TbFlow> list = iTbFlowService.list();
            return Result.ok(list);

        } catch (Exception e) {
            e.printStackTrace();
            // 查询数据库出现异常
            return Result.error();
        }
    }
}
